// --------------------------------------------------------------------------------------------------------------------
// <copyright file="LayerPlugin.cs" company="Open Trader">
//   Copyright (c) David Denis (david.denis@systemathics.com)
// </copyright>
// <summary>
//   |  Open Trader - The Open Source Systematic Trading Platform
//   |
//   |  This program is free software: you can redistribute it and/or modify
//   |  it under the terms of the GNU General Public License as published by
//   |  the Free Software Foundation, either version 2 of the License, or
//   |  (at your option) any later version.
//   |
//   |  This program is distributed in the hope that it will be useful,
//   |  but WITHOUT ANY WARRANTY; without even the implied warranty of
//   |  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//   |  GNU General Public License for more details.
//   |
//   |  You should have received a copy of the GNU General Public License
//   |  along with this program.  If not, see http://www.gnu.org/licenses
//   |
//   |  Up to date informations about Open Trader can be found at :
//   |    http://opentrader.org
//   |    http://opentrader.codeplex.com
//   |
//   |  For professional services, please visit us at :
//   |    http://www.systemathics.com
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Org.OpenTrader.Framework.Forge
{
    #region Using Directives

    using Org.OpenTrader.Framework.Enums;
    using Org.OpenTrader.Framework.Forge.Events;
    using Org.OpenTrader.Framework.Forge.Interfaces;
    using Org.OpenTrader.Framework.LiveObjects;
    using Org.OpenTrader.Framework.LiveObjects.Interfaces;

    #endregion

    /// <summary>
    /// The layer plugin.
    /// </summary>
    public abstract class LayerPlugin : Plugin, ILayer
    {
        #region Constants and Fields

        /// <summary>
        /// The identity.
        /// </summary>
        private static readonly Identity Identity = Identity.Create(System.Reflection.MethodBase.GetCurrentMethod());

        #endregion

        #region Constructors and Destructors

        /// <summary>
        /// Initializes a new instance of the <see cref="LayerPlugin"/> class.
        /// </summary>
        /// <param name="descriptor">
        /// The descriptor.
        /// </param>
        /// <param name="container">
        /// The container.
        /// </param>
        public LayerPlugin(ILiveObjectDescriptor descriptor, ILiveObjectContainer container)
            : base(descriptor, container)
        {
            this.ConnectionEventCB = new RemotableEventHandler<ConnectionEventArgs>(Identity + "EventCB");
        }

        #endregion

        #region Properties

        /// <summary>
        /// Gets or sets Connection.
        /// </summary>
        public IConnection Connection { get; protected set; }

        /// <summary>
        /// Gets ConnectionEventCB.
        /// </summary>
        public RemotableEventHandler<ConnectionEventArgs> ConnectionEventCB { get; set; }

        /// <summary>
        /// Gets Status.
        /// </summary>
        public abstract EConnectionStatus ConnectionStatus { get; }

        /// <summary>
        /// Gets ConnectionURL.
        /// </summary>
        public abstract string ConnectionURL { get; }

        #endregion

        #region Implemented Interfaces

        #region ILayer

        /// <summary>
        /// The connect.
        /// </summary>
        /// <returns>
        /// </returns>
        public abstract Status Connect();

        /// <summary>
        /// The disconnect.
        /// </summary>
        /// <returns>
        /// </returns>
        public abstract Status Disconnect();

        #endregion

        #endregion

        #region Methods

        /// <summary>
        /// The connection_ connection event cb.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        private void OnConnectionEventCB(object sender, ConnectionEventArgs e)
        {
            this.ConnectionEventCB.RaiseEvent(this, e);
        }

        #endregion
    }
}